<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('问卷管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>问卷标题：</label>
                                <input type="text" name="title"/>
                            </li>
                            <!--<li>
                                <label>活动开始时间：</label>
                                <input type="text" class="time-input" placeholder="请选择活动开始时间" name="startTime"/>
                            </li>
                            <li>
                                <label>活动结束时间：</label>
                                <input type="text" class="time-input" placeholder="请选择活动结束时间" name="endTime"/>
                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="ask:question:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="ask:question:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="ask:question:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="ask:question:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('ask:question:edit')}]];
        var updateFlag = [[${@permission.hasPermi('ask:question:updateFlag')}]];
        var removeFlag = [[${@permission.hasPermi('ask:question:remove')}]];
        var prefix = ctx + "ask/question";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "问卷管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'title',
                    title: '问卷标题'
                },
                /*{
                    field: 'content',
                    title: '问卷说明',
                    formatter:function (value,row,index){
                        var actions = [];
                        var html=row.content;
                        if (html.length>30){
                            html=html.substr(0,30);
                        }
                        actions.push('<div title="' + row.content + '">'+html+' </div>');
                        return actions.join('');
                    }
                },*/

                {
                    field: 'shareTitle',
                    title: '分享标题',
                    visible: false
                },
                {
                    field: 'shareContent',
                    title: '分享内容',
                    visible: false
                },
                {
                    field: 'sharePic',
                    title: '分享缩略图',
                    formatter:function (value,row,index){
                        var actions = [];
                        actions.push('<img src=' + row.sharePic + ' width="50px" height="50px"> ');
                        return actions.join('');
                    },
                    visible: false
                },
                {
                    field: 'music',
                    title: '背景音乐',
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注',
                    visible: false
                },

                {
                    field: 'zhuliScore',
                    title: '好友助力得分'
                },
                {
                    field: 'maxDaTiNum',
                    title: '最大答题次数'
                },
                {
                    field: 'status',
                    title: '上架状态',
                    formatter:function (value,row,index){
                        var actions = [];
                        if (row.status ==1 ){
                            actions.push('<font color="green">上架</font>');
                        }
                        if (row.status ==0 ){
                            actions.push('<font color="red">已下架</font>');
                        }
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.status==1){
                            actions.push('<a class="btn btn-success btn-xs ' + updateFlag + '" href="javascript:void(0)" onclick="updateFlg(\'' + row.id + '\',1)"><i class="fa fa-edit"></i>下架</a> ');
                        }else{
                            actions.push('<a class="btn btn-success btn-xs ' + updateFlag + '" href="javascript:void(0)" onclick="updateFlg(\'' + row.id + '\',0)"><i class="fa fa-edit"></i>上架</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function updateFlg(id,value){
            var message="下架";
            var status=0;
            if (value ==0){
                message="上架";
                status=1;
            }else{
                status=0;
            }
            $.modal.confirm("确认要" + message + "吗?", function() {
                var url = prefix + "/edit";
                var data = { "id": id,"status":status };
                $.operate.submit(url, "post", "json", data);
            });
        }
    </script>
</body>
</html>